package com.ctshk.rpc.scenic.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.common.dto.Result;
import com.ctshk.common.utils.DateUtil;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.rpc.scenic.dto.ScenicProductCostStrategySpecStockDTO;
import com.ctshk.rpc.scenic.entity.ScenicProductCostStrategySpecStock;
import com.ctshk.rpc.scenic.entity.ScenicProductCostStrategyVaildDate;
import com.ctshk.rpc.scenic.entity.ScenicProductTicket;
import com.ctshk.rpc.scenic.mapper.ScenicProductCostStrategySpecStockMapper;
import com.ctshk.rpc.scenic.mapper.ScenicProductCostStrategyVaildDateMapper;
import com.ctshk.rpc.scenic.req.ScenicProductCostStrategySpecStockReq;
import com.ctshk.rpc.scenic.req.ScenicResourceTicketReq;
import com.ctshk.rpc.scenic.service.ScenicProductCostStrategySpecStockService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;

/**
 * <p>
 * 门票库存 服务类
 * </p>
 *
 * @author chenlei
 * @since 2021-04-22
 */
@DubboService
public class ScenicProductCostStrategySpecStockServiceImpl extends ServiceImpl<ScenicProductCostStrategySpecStockMapper, ScenicProductCostStrategySpecStock> implements ScenicProductCostStrategySpecStockService {

    @Autowired
    private ScenicProductCostStrategyVaildDateMapper scenicProductCostStrategyVaildDateMapper;
    @Autowired
    private ScenicProductCostStrategySpecStockMapper scenicProductCostStrategySpecStockMapper;
    @Override
    public Result<ScenicProductCostStrategySpecStockDTO> querDetail(ScenicProductCostStrategySpecStockReq specStockReq) {
        //生成当前时间
        String time = DateUtil.fmt(LocalDateTime.now());
        ScenicProductCostStrategyVaildDate strategyVaildDate = scenicProductCostStrategyVaildDateMapper.queryDetail(time,specStockReq.getProductId());
        ScenicProductCostStrategySpecStockDTO dto = null;
        Long id = 0L;
        if(strategyVaildDate != null){
            ScenicProductCostStrategySpecStockReq req = new ScenicProductCostStrategySpecStockReq();
            req.setProductId(strategyVaildDate.getProductId());
            req.setStrategyId(strategyVaildDate.getStrategyId());
            req.setAttr1Name(specStockReq.getAttr1Name());
            req.setAttr2Name(specStockReq.getAttr2Name());
            dto = scenicProductCostStrategySpecStockMapper.queruDetail(req);
        }
        return Result.success(dto);
    }

    @Override
    public ScenicProductCostStrategySpecStockDTO selectById(Long id) {
        ScenicProductCostStrategySpecStockDTO strategySpecStockDto = new ScenicProductCostStrategySpecStockDTO();
        ScenicProductCostStrategySpecStock specStockDto = scenicProductCostStrategySpecStockMapper.selectById(id);
        if (null != specStockDto){
            strategySpecStockDto.setAttr1Name(specStockDto.getAttr1Name());
            strategySpecStockDto.setAttr2Name(specStockDto.getAttr2Name());
        }

        return strategySpecStockDto;
    }
}
